#define _CRT_SECURE_NO_WARNINGS 1
#include <stdlib.h>
struct Node {
    int val;
    struct Node* next;
    struct Node* random;
    
};
 
struct Node* copyRandomList(struct Node* head) {
    struct Node* q = head;
    while (q)
    {
        struct Node* copy = (struct Node*)malloc(sizeof(struct Node));
        copy->next = q->next;
        q->next = copy;
        copy->val = q->val;
        q = copy->next;
    }

    while (q)
    {
        struct Node* copy = q->next;
        if (q->random == NULL)
        {
            copy->random = NULL;
        }
        else
        {
            copy->random = q->random->next;
        }
        q = copy->next;
    }
    q = head;
    struct Node* han = q->next;
    while (q)
    {
        struct Node* fan = q->next;
        q = fan->next;
        if (fan->next != NULL)
        {
            fan->next = q->next;
        }
    }

    return han;
}
